class MyPromise {
  constructor(executor) {
    this.state = 'pending'
    this.value = ''
    this.reason = ''
    let resolve = (value) => {
      console.log("这里是测试resolve传入的形参",value);
      if (this.state === 'pending') {
        this.state = 'fullFilled'  //改变状态
        this.value = value   //存入形参的值
      }
    }
    let reject = (reason) => {
      if (this.state === 'pending') {
        this.state = 'rejected'
        this.reason = reason
      }
    }
    try{
      executor(resolve, reject)
    }
    catch {
      reject(reason)
    }
  }
  then(onFullFilled, onRejected) {
    console.log('then方法', this.state);
    if (this.state === 'fullFilled'){
      onFullFilled(this.value)
    }
    if (this.state === 'rejected'){
      onRejected(this.reason)
    }
  }
} 

module.exports = {
  MyPromise
}